Persistent Volume

Here's the technical breakdown of using VirtualBox Shared Folders vs NFS for persistent storage in your k3s cluster:


1. Technical Possibility

Yes, you can use VirtualBox Shared Folders as persistent storage through hostPath volumes, but with significant limitations compared to NFS.


2. Implementation Method

Step 1: Mount Shared Folder in VMs

# On both VM1 and VM2
sudo mount -t vboxsf <shared_folder_name> /mnt/shared

Step 2: Create PersistentVolume

apiVersion: v1
kind: PersistentVolume
metadata:
  name: vbox-shared-pv
spec:
  capacity:
    storage: 100Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /mnt/shared
    type: Directory

Step 3: Create PersistentVolumeClaim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: vbox-shared-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

3. Critical Limitations ⚠️

Aspect VirtualBox Shared Folders NFS
Concurrent Access Single-writer only Multi-writer supported
File Locking No proper advisory locks Full locking support
Permissions UID/GID mapping issues POSIX permissions
Performance Slow for small files Better throughput
Pod Scheduling Tied to specific nodes Any node
Atomic Renames Not supported Supported
Symlinks Partial support Full support

4. Specific Application Risks 🚨

  1. Database Corruption (Vaultwarden/PostgreSQL):
    # Common error you might see:
    FATAL:  could not flush dirty data: Invalid argument
  2. File Locking Issues (Paperless-ngx/Nextcloud):
    Error: Failed to acquire advisory lock on file
  3. Permission Mismatches:
    www-data user cannot write to shared folder

If you still want to proceed:

  1. Use only for read-only volumes
  2. Add to pod specs:
    securityContext:
    runAsUser: 1000
    fsGroup: 1000
  3. Regular backups:
    # Add to crontab
    0 * * * * rsync -a /mnt/shared/ /mnt/backup/$(date +\%s)

6. Better Alternative

Use NFS through VirtualBox Shared Folders:

  1. On Physical Machine 1:
    # Share via NFS instead of vboxsf
    /mnt/host-share 192.168.123.221(rw,sync) 192.168.123.222(rw,sync)
  2. Mount in VMs:
    mount -t nfs 192.168.123.100:/mnt/host-share /mnt/nfs-share

7. When to Consider Shared Folders

  • Single-node development clusters
  • Read-only configmaps/secrets
  • Temporary scratch space
  • Non-critical data with regular backups

For your production-like home lab with stateful applications, NFS remains the better choice for data integrity and multi-node access.

This page was last edited on 2025-03-07 16:39

Powered by Wiki|Docs

This page was last edited on 2025-03-07 16:39

Mac
To whom it may concern

Powered by Wiki|Docs